home *** CD-ROM | disk | FTP | other *** search
- #include "vbc.h"
-
- void simple_regs(void)
- /* haelt Variablen in Registern, simple Version */
- {
- int i2,i,j;int pri;struct Var *v;
- struct IC *icp,*start=first_ic;
- if(!first_ic) return;
- for(i2=0;i2<=MAXR*4;i2++){
- int only_best,pointertype;
- if(i2<=MAXR*2){i=i2;only_best=1;} else {i=i2/2;pointertype=only_best=0;}
- if(i>MAXR){
- i-=MAXR;
- if(regsv[i]) continue;
- }else{
- regsv[i]=0;
- /* Ziehe Scratchregister vor, wenn kein Funktionsaufruf */
- /* erfolgt, sonst erst andere */
- if(!function_calls&&!regscratch[i]) continue;
- if(function_calls&®scratch[i]) continue;
- }
- if(regused[i]) continue;
- /* Nicht-Scratchregister muessen einmal gesichert und wieder */
- /* hergestellt werden, Scratchregister bei jedem Call */
- if(regscratch[i]) pri=function_calls*2; else /*pri=2;*/ pri=0;
- for(j=0;j<=1;j++){
- if(j==0) v=merk_varf; else v=first_var[1];
- while(v){
- if(v->storage_class==AUTO||v->storage_class==REGISTER){
- if(!(v->flags&USEDASADR)&&!(v->vtyp->flags&VOLATILE)){
- if(only_best&&v->vtyp->next) pointertype=v->vtyp->next->flags;
- if(v->priority>pri&®ok(i,v->vtyp->flags&31,pointertype)){
- regsv[i]=v;pri=v->priority;
- }
- }
- }
- v=v->next;
- }
- }
- if(regsv[i]){
- if(DEBUG&1) printf("Assigned <%s> to %s\n",regsv[i]->identifier,regnames[i]);
- regsv[i]->priority=0;regused[i]=1;
- if(regsv[i]->offset<0&&!(regsv[i]->flags&CONVPARAMETER)){
- icp=(struct IC *)mymalloc(ICS);
- icp->q1.am=icp->q2.am=icp->z.am=0;
- icp->code=ASSIGN;
- icp->typf=regsv[i]->vtyp->flags&31;
- icp->q1.flags=VAR;
- icp->q1.v=regsv[i];
- icp->q1.val.vlong=l2zl(0L);
- icp->q2.flags=0;
- icp->q2.reg=szof(regsv[i]->vtyp);
- icp->z.flags=REG;
- icp->z.reg=i;
- icp->next=first_ic;
- icp->prev=0;
- first_ic->prev=icp;
- first_ic=icp;
- }
- icp=(struct IC *)mymalloc(ICS);
- icp->q1.am=icp->q2.am=icp->z.am=0;
- icp->code=ALLOCREG;
- icp->q1.flags=REG;
- icp->q1.reg=i;
- icp->q2.flags=icp->z.flags=icp->typf=0;
- icp->next=first_ic;
- icp->prev=0;
- first_ic->prev=icp;
- first_ic=icp;
- icp=(struct IC *)mymalloc(ICS);
- icp->q1.am=icp->q2.am=icp->z.am=0;
- icp->code=FREEREG;
- icp->q1.flags=REG;
- icp->q1.reg=i;
- icp->q2.flags=icp->z.flags=icp->typf=0;
- icp->next=0;
- add_IC(icp);
- }
- }
- icp=start;
- while(icp){
- if((icp->code==ALLOCREG||icp->code==FREEREG)&®sv[icp->q1.reg]){
- /* irgendwelche allocreg/freereg im Code entfernen */
- /* sollte nur beim Returnregister vorkommen */
- struct IC *m=icp->next;
- remove_IC(icp);
- icp=m;continue;
- }
- for(i=1;i<=MAXR;i++){
- if(!regsv[i]) continue;
- if((icp->q1.flags&(VAR|DONTREGISTERIZE))==VAR&&icp->q1.v==regsv[i]){
- icp->q1.flags|=REG;
- icp->q1.reg=i;
- }
- if((icp->q2.flags&(VAR|DONTREGISTERIZE))==VAR&&icp->q2.v==regsv[i]){
- icp->q2.flags|=REG;
- icp->q2.reg=i;
- }
- if((icp->z.flags&(VAR|DONTREGISTERIZE))==VAR&&icp->z.v==regsv[i]){
- icp->z.flags|=REG;
- icp->z.reg=i;
- }
- }
- icp=icp->next;
- }
- }
-
-